/*****************************************************************************
 * Please See the declaration in the bottom of this file.
 *
 *
 * Version			Date				Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Init(0)			2007.08.20 
 *****************************************************************************/
 
#ifndef		__SM59R16A2_ExtraDef_H__
#define		__SM59R16A2_ExtraDef_H__


//===============================
//Power Control, PCON = 0x87
//===============================
#define MSK_PCON_SMOD		0x80
#define PCON_SMOD32		MSK_PCON_SMOD
#define PCON_SMOD64		0x00

#define MSK_PCON_MDUF		0x40
#define MSK_PCON_PMW		0x10
#define PCON_PROGMEM_WR		MSK_PCON_PMW

#define MSK_PCON_STOP		0x02
#define PCON_STOP		MSK_PCON_STOP

#define MSK_PCON_IDLE		0x01
#define PCON_IDLE		MSK_PCON_IDLE


//===============================
//Timer/Counter Control, TCON = 0x88
//===============================
#define T1_OVIF			TCON_TF1
#define T1_RUN			TCON_TR1

#define T0_OVIF			TCON_TF0
#define T0_RUN			TCON_TR0

#define INT1IF			TCON_IE1
#define INT1_FALLEDGE		0x04
#define INT1_LOWLEVEL		0x00

#define INT0IF			TCON_IE0
#define INT0_FALLEDGE		0x01
#define INT0_LOWLEVEL		0x00


/*
IT1:	Interrupt 1 type control bit. Selects falling edge or low level on input pin to cause interrupt.
IT0:	Interrupt 0 type control bit. Selects falling edge or low level on input pin to cause interrupt.
*/

//===============================
//Timer Mode Control, TMOD = 0x89
//===============================
#define T1_GATE_EN		0x80
#define T1_ASCOUNTER		0x40
#define T1_13B_MODE		0x00
#define T1_16B_MODE		0x10
#define T1_8BREL_MODE		0x20
#define T1_STOPMODE		0x30
		
#define T0_GATE_EN		0x08
#define T0_ASCOUNTER		0x04
#define T0_13B_MODE		0x00
#define T0_16B_MODE		0x01
#define T0_8BREL_MODE		0x02
#define T0_IND8BMODE		0x03


//===============================
//Interface control register, IFCON = 0x8F
//===============================
#define MSK_IFCON_ITS		0x80
#define INSTRMODE_2T		0x00
#define INSTRMODE_1T		MSK_IFCON_ITS

#define MSK_IFCON_ALEC		0x0C
#define ALEOUT_ALWAYSE		0x00
#define ALEOUT_NO		0x04 
#define ALEOUT_ONLYRW		0x08

#define MSK_IFCON_DMEN		0x02
#define INT2KRAM_EN		0x00
#define INT2KRAM_DIS		MSK_IFCON_DMEN


//===============================
//Data Pointer select Register, DPS = 0x92
//===============================
#define MSK_DPS_DPS		0x01
#define DPS_SELDPTR1		MSK_DPS_DPS


//===============================
//Keyboard level selector register, KBLS = 0x93
//===============================
#define MSK_KBLS_ENH7		0x80
#define MSK_KBLS_ENH6		0x40
#define MSK_KBLS_ENH5		0x20
#define MSK_KBLS_ENH4		0x10
#define MSK_KBLS_ENH3		0x08
#define MSK_KBLS_ENH2		0x04
#define MSK_KBLS_ENH1		0x02
#define MSK_KBLS_ENH0		0x01


//===============================
//Keyboard input enable register, KBE = 0x94
//===============================
#define MSK_KBE_ENINT7		0x80
#define MSK_KBE_ENINT6		0x40
#define MSK_KBE_ENINT5		0x20
#define MSK_KBE_ENINT4		0x10
#define MSK_KBE_ENINT3		0x08
#define MSK_KBE_ENINT2		0x04
#define MSK_KBE_ENINT1		0x02
#define MSK_KBE_ENINT0		0x01


//===============================
//Keyboard interrupt flag register, KBF = 0x95
//===============================
#define MSK_KBF_F7		0x80
#define MSK_KBF_F6		0x40
#define MSK_KBF_F5		0x20
#define MSK_KBF_F4		0x10
#define MSK_KBF_F3		0x08
#define MSK_KBF_F2		0x04
#define MSK_KBF_F1		0x02
#define MSK_KBF_F0		0x01


//===============================
//Serial Port 0, Control Register, S0CON = 0x98
//===============================
#define MSK_S0CON_MODE		0xC0
#define S0CON_MODE0		0x00
#define S0CON_MODE1		0x40
#define S0CON_MODE2		0x80
#define S0CON_MODE3		MSK_S0CON_MODE

#define MSK_S0CON_SM20		0x20
#define MSK_S0CON_REN0		0x10
#define MSK_S0CON_TB80		0x08
#define MSK_S0CON_RB80		0x04
#define MSK_S0CON_TI0		0x02
#define MSK_S0CON_RI0		0x01


//===============================
//Interrupt Enable Register 2, IEN2 = 0x9A
//===============================
#define MSK_IEN2_ES1		0x01
#define S1INT_EN		MSK_IEN2_ES1


//===============================
//Serial Port 1, Control Register, S1CON = 0x9B
//===============================
#define MSK_S1CON_SM		0x80
#define S1CON_MODEA		0x00
#define S1CON_MODEB		MSK_S1CON_SM

#define MSK_S1CON_SM21		0x20
#define MSK_S1CON_REN1		0x10
#define MSK_S1CON_TB81		0x08
#define MSK_S1CON_RB81		0x04
#define MSK_S1CON_TI1		0x02
#define MSK_S1CON_RI1		0x01


//===============================
//Interrupt Enable Register 0, IEN0 = 0xA8
//===============================
#define MSK_IEN0_EA		0x80
#define ALLINT_EN		MSK_IEN0_EA

#define MSK_IEN0_ET2		0x20
#define T2INT_EN		MSK_IEN0_ET2

#define MSK_IEN0_ES0		0x10
#define S0INT_EN		MSK_IEN0_ES0

#define MSK_IEN0_ET1		0x08
#define T1INT_EN		MSK_IEN0_ET1

#define MSK_IEN0_EX1		0x04
#define EXINT1_EN		MSK_IEN0_EX1

#define MSK_IEN0_ET0		0x02
#define T0INT_EN		MSK_IEN0_ET0

#define MSK_IEN0_EX0		0x01
#define EXINT0_EN		MSK_IEN0_EX0


//===============================
//Interrupt Priority level Register 0, IP0 = 0xA9
//===============================
#define TIMER2_IP0		0x20
#define SERIAL0_IP0		0x10
#define TIMER1_IP0		0x08
#define INT1_IP0		0x04
#define TIMER0_IP0		0x02
#define INT0_IP0		0x01


//===============================
//ADC control register 1, ADCC1 = 0xAB
//===============================
#define MSK_ADCC1_ADC3E		0x08
#define ADCC3_EN		MSK_ADCC1_ADC3E

#define MSK_ADCC1_ADC2E		0x04
#define ADCC2_EN		MSK_ADCC1_ADC2E

#define MSK_ADCC1_ADC1E		0x02
#define ADCC1_EN		MSK_ADCC1_ADC1E

#define MSK_ADCC1_ADC0E		0x01
#define ADCC0_EN		MSK_ADCC1_ADC0E


//===============================
//ADC control register 2, ADCC2 = 0xAC
//===============================
#define MSK_ADCC2_COM		0x80
#define ADC_CONV_DONE		MSK_ADCC2_COM

#define MSK_ADCC2_START		0x40
#define ADC_CONV_START		MSK_ADCC2_START

#define MSK_ADCC2_ADC8B		0x20
#define ADC_8BIT		MSK_ADCC2_ADC8B
#define ADC_10BIT		0x00

#define MSK_ADCC2_ADCCH		0x0C
#define ADC_CH0_IN		0x00
#define ADC_CH1_IN		0x04
#define ADC_CH2_IN		0x08
#define ADC_CH3_IN		MSK_ADCC2_ADCCH

#define MSK_ADCC2_ADCCS		0x03
#define ADC_CLK_DIV8		0x00 
#define ADC_CLK_DIV16		0X01
#define ADC_CLK_DIV32		0x02 
#define ADC_CLK_DIV64		MSK_ADCC2_ADCCS 


//===============================
//PWM control register, PWMC = 0xB5
//===============================
#define MSK_PWMC_PWMM		0x30
#define PWM_8BMODE		0x00 
#define PWM_10BMODE		0x10
#define PWM_12BMODE		0x20

#define MSK_PWMC_PWM3EN		0x08
#define PWM_CH3_EN		MSK_PWMC_PWM3EN

#define MSK_PWMC_PWM2EN		0x04
#define PWM_CH2_EN		MSK_PWMC_PWM2EN

#define MSK_PWMC_PWM1EN		0x02
#define PWM_CH1_EN		MSK_PWMC_PWM1EN

#define MSK_PWMC_PWM0EN		0x01
#define PWM_CH0_EN		MSK_PWMC_PWM0EN


//===============================
//Watchdog timer control register, WDTC	= 0xB6
//===============================
#define MSK_WDTC_WDTF		0x80


//===============================
//Interrupt Enable Register 1, IEN1 = 0xB8
//===============================
#define MSK_IEN1_EXEN2		0x80
#define MSK_IEN1_IEIIC		0x20
#define IICINT_EN		MSK_IEN1_IEIIC

#define MSK_IEN1_IEKBI		0x08
#define KBIINT_EN		MSK_IEN1_IEKBI

#define MSK_IEN1_IEADC		0x04
#define ADCINT_EN		MSK_IEN1_IEADC

#define MSK_IEN1_IESPI		0x02
#define SPIINT_EN		MSK_IEN1_IESPI


//===============================
//Interrupt Priority level Register 1, IP1 = 0xB9
//===============================
#define TIMER2_IP1		0x20
#define SERIAL0_IP1		0x10
#define TIMER1_IP1		0x08
#define INT1_IP1		0x04
#define TIMER0_IP1		0x02
#define INT0_IP1		0x01


//===============================
//Interrupt Request Control Register, IRCON = 0xC0
//===============================
#define MSK_IRCON_EXF2		0x80
#define T2_EXTRELF		MSK_IRCON_EXF2

#define MSK_IRCON_TF2		0x40
#define T2_OVF			MSK_IRCON_TF2

#define MSK_IRCON_IICIF		0x20
#define IIC_IF			MSK_IRCON_IICIF

#define MSK_IRCON_KBIIF		0x08
#define KBI_IF			MSK_IRCON_KBIIF

#define MSK_IRCON_ADCIF		0x04
#define ADC_IF			MSK_IRCON_ADCIF

#define MSK_IRCON_SPIIF		0x02
#define SPI_IF			MSK_IRCON_SPIIF


//===============================
//Timer 2 Control, T2CON = 0xC8
//===============================
#define MSK_T2CON_T2PS		0x80
#define T2_CLK12		0x00
#define T2_CLK24		MSK_T2CON_T2PS

#define MSK_T2CON_CC0FR		0x40
#define T2_FALL_EDGE		0x00		
#define T2_RISE_EDGE		MSK_T2CON_CC0FR

#define MSK_T2CON_T2R		0x18
#define T2_REL_DIS		0x00		
#define T2_REL_MODE0		0x10
#define T2_REL_MODE1		MSK_T2CON_T2R

#define MSK_T2CON_T2CM		0x04
#define T2_CMP_MODE0		0x00
#define T2_CMP_MODE1		MSK_T2CON_T2CM

#define MSK_T2CON_T2I		0x03
#define T2_STOP			0x00
#define T2_INF			0x01
#define T2_EXF			0x02
#define T2_GATED		MSK_T2CON_T2I


//===============================
//Arithmetic Control register, ARCON = 0xEF
//===============================
#define MSK_ARCON_MDEF		0x80
#define MSK_ARCON_MDOV		0x40
#define MSK_ARCON_SLR		0x20
#define MSK_ARCON_SC		0x1F


//===============================
//SPI control register 1, SPIC1	= 0xF1
//===============================
#define MSK_SPIC1_SPIEN		0x80
#define SPI_EN			MSK_SPIC1_SPIEN

#define MSK_SPIC1_SPIMSS	0x40
#define SPI_MASTER		MSK_SPIC1_SPIMSS
#define SPI_SLAVE		0x00

#define MSK_SPIC1_SPISSP	0x20
#define SPI_SSP_HIGH		MSK_SPIC1_SPISSP
#define SPI_SSP_LOW		0x00

#define MSK_SPIC1_SPICKP	0x10
#define SPI_CKP_HIGH		MSK_SPIC1_SPICKP
#define SPI_CKP_LOW		0x00		

#define MSK_SPIC1_SPICKE	0x08
#define SPI_CKE_RISE		MSK_SPIC1_SPICKE
#define SPI_CKE_FALL		0x00		

#define MSK_SPIC1_SPIBR		0x07
#define SPI_BR4			0x00
#define SPI_BR8			0x01
#define SPI_BR16		0x02
#define SPI_BR32		0x03
#define SPI_BR64		0x04
#define SPI_BR128		0x05
#define SPI_BR256		0x06
#define SPI_BR512		MSK_SPIC1_SPIBR


//===============================
//SPI control register 2, SPIC2	= 0xF2
//===============================
#define MSK_SPIC2_SPIFD		0x80
#define SPI_FULLDUP_EN		MSK_SPIC2_SPIFD			
#define SPI_FULLDUP_DIS		0x00

#define MSK_SPIC2_TBC		0x70
#define SPI_TX_8B		0x00
#define SPI_TX_1B		0x10
#define SPI_TX_2B		0x20
#define SPI_TX_3B		0x30
#define SPI_TX_4B		0x40
#define SPI_TX_5B		0x50
#define SPI_TX_6B		0x60
#define SPI_TX_7B		MSK_SPIC2_TBC

#define MSK_SPIC2_RBC		0x07
#define SPI_RX_8B		0x00
#define SPI_RX_1B		0x01
#define SPI_RX_2B		0x02
#define SPI_RX_3B		0x03
#define SPI_RX_4B		0x04
#define SPI_RX_5B		0x05
#define SPI_RX_6B		0x06
#define SPI_RX_7B		MSK_SPIC2_RBC


//===============================
//SPI status register, SPIS = 0xF5
//===============================
#define MSK_SPIS_SPIMLS		0x40
#define SPI_MSB_FIRST		MSK_SPIS_SPIMLS
#define SPI_LSB_FIRST		0x00

#define MSK_SPIS_SPIOV		0x20
#define SPIOV_FLG		MSK_SPIS_SPIOV

#define MSK_SPIS_SPITXIF	0x10
#define SPI_TXIF		MSK_SPIS_SPITXIF

#define MSK_SPIS_SPITDR		0x08
#define SPI_TXD_RDY		MSK_SPIS_SPITDR

#define MSK_SPIS_SPIRXIF	0x04
#define SPI_RXIF		MSK_SPIS_SPIRXIF

#define MSK_SPIS_SPIRDR		0x02
#define SPI_RXD_RDY		MSK_SPIS_SPIRDR

#define MSK_SPIS_SPIRS		0x01
#define SPI_RX_START		MSK_SPIS_SPIRS
			

//===============================
//IIC control register, IICCTL = 0xF9
//===============================
#define MSK_IICCTL_IICEN	0x80 
#define IIC_EN			MSK_IICCTL_IICEN

#define MSK_IICCTL_BF		0x40
#define IIC_BUS_FAIL		MSK_IICCTL_BF			

#define MSK_IICCTL_MSS		0x20
#define IIC_MASTER		MSK_IICCTL_MSS
#define IIC_SLAVE		0x00

#define MSK_IICCTL_MAS		0x10 
#define IIC_ADR_CA1		0x00
#define IIC_ADR_CA2		MSK_IICCTL_MAS

#define MSK_IICCTL_RSTART	0x08 
#define IIC_RSTART		MSK_IICCTL_RSTART

#define MSK_IICCTL_IICBR	0x07
#define IIC_BR32		0x00
#define IIC_BR64		0x01
#define IIC_BR128		0x02
#define IIC_BR256		0x03
#define IIC_BR512		0x04
#define IIC_BR1024		0x05
#define IIC_BR2048		0x06
#define IIC_BR4096		MSK_IICCTL_IICBR


//===============================
//IIC Address 1 register, IICA1	= 0xFA
//===============================
#define MSK_IICA1_IICA1		0xFE
#define MSK_IICA1_Match1	0x01
#define MSK_IICA1_RW1		0x01


//===============================
//IIC Address 2 register, IICA2	= 0xFB
//===============================
#define MSK_IICA2_IICA2		0xFE
#define MSK_IICA2_Match2	0x01
#define MSK_IICA2_RW2		0x01



//===============================
//Frequent Definition
//===============================
#define	true	1
#define	false	0



//===============================
//Data type
//===============================
typedef	union {
		unsigned char	UByte[2];
		unsigned int	UInt;
       	      } UWORD;








#endif


/*****************************************************************************
 * Processor:	SM59R16A2
 * Compiler:	Keil C 2.0
 *
 * Company:	SyncMOS Technologies International,Inc.
 * Author:	Stanley Huang
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Board:	64-pin demo board (SDB0001A-0)
 * Purpose:
 *
 *
 *****************************************************************************/
